package com.yueya.common.city.model;

import java.util.List;

import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Record;
import com.yueya.common.city.service.CityService;

@SuppressWarnings("serial")
public class City extends Model<City> {
	
	public static City dao = new City();
	public static CityService service = new CityService();

	public List<City> getListByParentId(String id){
		if(StrKit.isBlank(id)) return null;
		return City.dao.find("SELECT * FROM w_city a WHERE parent_id=? AND del_flag='0'", id);
	}
	
	
	public Record getByNameLevel(String name ,int level){
		return Db.findFirst("select * from w_city where name like '"+name+"%'  and level =?",level );
	};
	
	public Record getByNameDomain(String name ,String domain){
		return Db.findFirst("select * from w_city where name like '"+name+"%'  and domain like '"+domain+"%' ");
	};
	public City findByNameAndLevel(String name, int level){
		if(StrKit.isBlank(name)) return null;
		return findFirst("SELECT * FROM w_city WHERE name LIKE '"+name+"%' AND level=?", level);
	}
	
	public City findByNameAndLevel(String name, int level, int parentId){
		if(StrKit.isBlank(name)) return null;
		return findFirst("SELECT * FROM w_city WHERE name LIKE '"+name+"%' AND level=? AND parent_id=?", level, parentId);
	}	
}
